package main

import "fmt"

/*
doctor是核心模块
*/
type doctor struct {
}

func (doctor) treatEyes() {
	fmt.Println("治疗眼...")
}

func (doctor) treatNose() {
	fmt.Println("治疗鼻...")
}

// Commander 创建命令接口 实现类调用核心模块的方法
type Commander interface {
	Treat()
}

type TreatEyes struct {
	doctor
}

func (t TreatEyes) Treat() {
	t.doctor.treatEyes()
}

type TreatNose struct {
	doctor
}

func (t TreatNose) Treat() {
	t.doctor.treatNose()
}

/*
命令调用者
*/
type Nurse struct {
	commandList []Commander
}

/*
调用命令的具体方法
*/
func (n Nurse) UseCommander() {
	for _, commander := range n.commandList {
		commander.Treat()
	}
}

func main() {
	d := new(doctor)
	eyes := TreatEyes{doctor: *d}
	nose := TreatNose{doctor: *d}
	n := new(Nurse)
	n.commandList = append(n.commandList, eyes)
	n.commandList = append(n.commandList, nose)
	n.UseCommander()
}
